<template>
  <base-breadcrumb>
    <searchData
      :search-data="searchArr"
      @search="search"
    />
    <a-card>
      <list-table
        ref="table"
        :columns="columns"
        :request="loadData"
        :statistics-config=" {use: true,statistics}"
      >
        <template
          slot="prefix"
          slot-scope="ref"
        >
          <a-button
            v-btn-permission="'lcm_002_add_01'"
            type="primary"
            icon="plus"
            @click="getDetail(null,1)"
          >
            新增招议标计划
          </a-button>
        </template>
        <template
          slot="auditStatusEnumStr"
          slot-scope="text, record, index"
        >
          <list-status
            :status="record.auditStatusEnum"
            :text="text"
          />
        </template>
        <template
          slot="action"
          slot-scope="text, record"
        >
          <MoreButton>
            <a @click="getDetail(record,3)">查看</a>
            <template v-if="record.auditStatusEnum === 'DRAFT' || record.auditStatusEnum === 'REJECTED'">
              <a @click=" getDetail(record,2)">编辑</a>
              <a @click="handleDel(record.id)">删除</a>
            </template>
            <approval-button
              :id="record.id"
              :status="record.auditStatusEnum"
              v-if="record.auditStatusEnum === 'PAST' || record.auditStatusEnum === 'SUBMITTED' || record.auditStatusEnum === 'REJECTED' || record.auditStatusEnum === 'REVOKEIN' || record.auditStatusEnum === 'REVOKE' || record.auditStatusEnum === 'ABOLISH' || record.auditStatusEnum === '1' || record.auditStatusEnum === '3' || record.auditStatusEnum === 'COMMIT'|| record.auditStatusEnum === '2' "
            />
          </MoreButton>
        </template>
        <template
          slot="expandedRowRender"
          slot-scope="record"
        >
          <p><span>计划合同签订时间： </span><span>{{ record.planContractTime }}</span></p>
          <p><span>分包工程招标内容: </span><span>{{ record.biddingContent }}</span></p>
          <p><span>计划完工时间: </span><span>{{ record.planEndTime }}</span></p>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import {
    getBranchBiddingDiscussionList,
    getDropDown,
    deleteBySubContractPlanOut,
    findListCount
} from '@/api/legal'
import SelectSubCompany from "@/components/Select/SelectSubCompany"
import SelectProject from "@/components/Select/SelectProject"

export default {
  name:'a'+Date.now(),
    components: {
    },
    data() {
        return {
            statistics: {},
            columns: [
                {
                    title: '所属分公司',
                    dataIndex: 'branchCompany'
                },
                {
                    title: '项目名称',
                    dataIndex: 'projectName'
                },
                {
                    title: '招标内容 ',
                    dataIndex: 'biddingContent',
                    width: '340px',
                    ellipsis: true
                },
                {
                    title: '招标合同额（万元）',
                    dataIndex: 'tenderContractMoney',
                    width: '200px',
                },
                {
                    title: '分包商选择方式',
                    dataIndex: 'subcontractorsSelect',
                    width: '200px',
                },
                {
                    title: '分包方式',
                    dataIndex: 'branchPackMode'
                },
                {
                    title: '计划招议标时间',
                    dataIndex: 'planBiddingTime',
                    width: '160px',

                },
                {
                    title: '计划开工时间',
                    dataIndex: 'planTime'
                },
                {
                    title: '审批状态',
                    dataIndex: 'auditStatusEnumStr',
                    scopedSlots: { customRender: 'auditStatusEnumStr' }
                },
                {
                    title: '创建时间',
                    dataIndex: 'createTime',
                    width: '180px',
                },
                {
                    title: '操作',
                    width: '160px',
                    height: '100%',
                    fixed: 'right',
                    scopedSlots: { customRender: 'action' }
                }
            ],
            searchArr: [
                // 搜索框
                {
                    name: '所属分公司',
                    type: SelectSubCompany,
                    valueKey: 'branchCompanyId'
                },
                {
                    name: '项目名称',
                    type: SelectProject,
                    valueKey: 'projectId'
                },
                {
                    name: '计划开工时间',
                    value: 'plan',
                    type: 'dateRangeFormat'
                },
                {
                    name: '计划招议标时间',
                    value: 'planBidding',
                    type: 'dateRangeFormat'
                },
                {
                    name: '分包方式',
                    value: 'branchPackMode',
                    type: 'select',
                    data: [],
                    request: () => getDropDown({ query: { type: 0 } })
                },
                {
                    name: '状态',
                    value: 'auditStatusEnum',
                    type: 'select',
                    data: this.STATUS
                },
                {
                    name: '招标合同额开始',
                    value: 'tenderContractStartMoney',
                    type: 'input'
                },
                {
                    name: '招标合同额结束',
                    value: 'tenderContractEndMoney',
                    type: 'input'
                },
                {
                    name: '创建时间',
                    value: 'create',
                    type: 'dateRangeFormat'
                }
            ],
            queryParam: {},
            loadData: parameter => {
                const searchData = Object.assign({}, parameter, this.queryParam)
                findListCount(searchData).then(res => {
                    if (res.code === this.SUCCESS_CODE) this.statistics = res.data
                })
                return getBranchBiddingDiscussionList(searchData).then(res => {
                    return res
                })
            }
        }
    },
    methods: {
        handleDel(id) {
            let params = id ? [id] : this.selectId
            this.$delList2(deleteBySubContractPlanOut, () => {
                this.$refs.table.getData(null, true)
            }, { ids: params })
        },
        search(val) {
            this.queryParam = val
            if (val.planBidding && val.planBidding.length) {
                this.queryParam.planBiddingStartTime = val.planBiddingStartTime.substr(0, 10)
                this.queryParam.planBiddingEndTime = val.planBiddingEndTime.substr(0, 10)
            }
            if (val.plan && val.plan.length) {
                this.queryParam.planStartTime = val.planStartTime.substr(0, 10)
                this.queryParam.planEndTime = val.planEndTime.substr(0, 10)
            }

            if (val.create && val.create.length) {
                this.queryParam.createStartTime = new Date(val.createStartTime).valueOf()
                this.queryParam.createEndTime = new Date(val.createEndTime.substr(0, 11) + '23:59:59').valueOf()
            }
            this.$refs.table.getData(null, true)
        },
        getDetail(record, state) {
            this.$router.push({
                path: '/legal/branch-bidding/plandiscussion/detail',
                query: {
                    id: record && record.id,
                    state
                }
            })
        }
    }
}
</script>
